﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using System.Web;
using Antu.WorkFlowFactory;
using System.Data;

namespace WebSys.UI.OfficeFlow
{
    public class MemberMisSkin : MPBasicTemplate
    {
        FlowFactoryProvider _FlowFactoryProvider = (FlowFactoryProvider)ProviderService.ProviderServiceMange.GetProvider("FlowFactoryProvider");
        Button btnQuery, btnSave;
        TextBox useridlist, txtName;
        Literal Literal1;
        MPRepeater MPRepeater1;
        protected string UserId
        {
            get { if (base.Page.Session["UserId"] != null) { return base.Page.Session["UserId"].ToString(); } else { return string.Empty; } }
            set { base.Page.Session["UserId"] = value; }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            InitControl();
            if (!Page.IsPostBack)
            {
                string groupId = base.Page.Request["groupid"];
                Literal1.Text = _FlowFactoryProvider.GetOneStrString("st_group", "GROUP_NAME", "GROUPID", groupId);
                BindData();
            }
        }
        private void InitControl()
        {
            useridlist = (TextBox)FindControl("useridlist");
            txtName = (TextBox)FindControl("txtName");
            btnQuery = (Button)FindControl("btnQuery");
            btnSave = (Button)FindControl("btnSave");
            btnQuery.Click += new EventHandler(btnQuery_Click);
            btnSave.Click += new EventHandler(btnSave_Click);
            MPRepeater1 = (MPRepeater)FindControl("MPRepeater1");
            Literal1 = (Literal)FindControl("Literal1");
        }

        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindData();
        }
        protected void BindData() {
            string userName = txtName.Text;
            string groupId = base.Page.Request["groupid"];
            DataTable dt = _FlowFactoryProvider.GetAllUserTemp(groupId, userName);
            MPRepeater1.DataSource = dt;
            MPRepeater1.DataBind();
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string groupId = base.Page.Request["groupid"];
            for (int temp = 0; temp < MPRepeater1.Items.Count; temp++)
            {
                Label idtib = (Label)MPRepeater1.Items[temp].FindControl("idtib");
                CheckBox checkselect = (CheckBox)MPRepeater1.Items[temp].FindControl("checkselect");
                string userId = idtib.Text.Trim();
                int tt = _FlowFactoryProvider.GetUserGptNum(userId, groupId);
                if (checkselect.Checked)
                { if (tt == 0) { _FlowFactoryProvider.InsertUserGpt(userId, groupId); } }
                else { if (tt > 0) { _FlowFactoryProvider.DeleteUserGpt(userId, groupId); } }
            }
            Antu.Utilities.UtilitiesPage.RegJsScript(string.Format("window.location.href('MemberMis.aspx?groupid={0}');", groupId));
        }

    }
}


